package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class JDBCDemo1 {
    public static void main(String[] args) throws Exception {
        /*
        使用JDBC操作数据库的基本流程
        1：加载驱动
        2：通过DriverManager与数据库建立连接，创建Connection对象
        3：通过Connection对象创建Statement对象
        4：通过Statement对象执行SQL语句，得到结果集ResultSet对象
         */
        Class.forName("com.mysql.cj.jdbc.Driver");
      Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true","root","root");
        System.out.println("与数据库建立连接");
        Statement statement = connection.createStatement();
String sql="CREATE TABLE userinfo(" +
        "    id INT PRIMARY KEY AUTO_INCREMENT," +
        "    username VARCHAR(32)," +
        "    password VARCHAR(32)," +
        "    nickname VARCHAR(32)," +
        "    age INT(3)" +
        ")";
        statement.execute(sql);
        System.out.println("创建表成功");






    }
}
